//
//  WZGOrderPayHeadView.m
//  ZCJZ
//
//  Created by sujeking on 2019/8/27.
//  Copyright © 2019 jeking. All rights reserved.
//

#import "WZGOrderPayHeadView.h"

@interface WZGOrderPayHeadView()

@property (weak, nonatomic) IBOutlet UILabel *tiplabel;

@property (weak, nonatomic) IBOutlet UILabel *lllabel;
@property (weak, nonatomic) IBOutlet UILabel *lrlabel;
@property (weak, nonatomic) IBOutlet UILabel *rllabel;
@property (weak, nonatomic) IBOutlet UILabel *rrlabel;

@property (nonatomic, strong) NSTimer *timer;

@end

@implementation WZGOrderPayHeadView


- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupSubViews];
}

- (void)dealloc {
    [self.timer invalidate];
    self.timer = nil;
}

- (void)emptyLabeltext {
    self.lllabel.text = @"0";
    self.lrlabel.text = @"0";
    self.rllabel.text = @"0";
    self.rrlabel.text = @"0";
}

- (void)setupSubViews {
    self.lllabel.layer.cornerRadius = 3.0f;
    self.lllabel.layer.masksToBounds = YES;
    self.lrlabel.layer.cornerRadius = 3.0f;
    self.lrlabel.layer.masksToBounds = YES;
    self.rllabel.layer.cornerRadius = 3.0f;
    self.rllabel.layer.masksToBounds = YES;
    self.rrlabel.layer.cornerRadius = 3.0f;
    self.rrlabel.layer.masksToBounds = YES;
    
    [self emptyLabeltext];
}

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    __block NSInteger sc = [[dict valueForKey:@"pay_overtime"] integerValue];
    if (sc == 0) {
        [self emptyLabeltext];
        return;
    }
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        NSInteger mi = sc / 60;
        NSInteger scs = sc % 60;
        self.lllabel.text = [NSString stringWithFormat:@"%ld",mi/10];
        self.lrlabel.text = [NSString stringWithFormat:@"%ld",mi%10];
        self.rllabel.text = [NSString stringWithFormat:@"%ld",scs/10];
        self.rrlabel.text = [NSString stringWithFormat:@"%ld",scs%10];
        sc--;
        
        if (sc == 0) {
            [self.timer invalidate];
            self.timer = nil;
        }
    }];
}

@end
